// import {message} from 'antd';
import { feedbackRecordList, feedbackTypeList } from './service';

import { ModelType } from '@/common-typings.d';
import types from '@/const/constType';

const { CODE } = types;

const Model: ModelType = {
  namespace: 'news',
  state: {
    // 站内信
    mail: {
      feedbackRecordList: [],
      feedbackTypeList: [],
    },
  },

  effects: {
    *feedbackRecordList({ payload, fn }, { call, put }) {
      const response = yield call(feedbackRecordList, payload);
      if (response.code === CODE) {
        yield put({ type: 'setFeedbackRecordList', payload: response });
        if (fn) {
          fn(response.data);
        }
      }
    },
    *feedbackTypeList({ payload }, { call, put }) {
      const response = yield call(feedbackTypeList, payload);
      if (response.code === CODE) {
        yield put({ type: 'setFeedbackTypeList', payload: response });
      }
    },
  },
  reducers: {
    setFeedbackRecordList(state, { payload }) {
      const newState = JSON.parse(JSON.stringify(state));
      newState.mail.feedbackRecordList = payload.data;
      return {
        ...state,
        ...newState,
      };
    },
    setFeedbackTypeList(state, { payload }) {
      const newState = JSON.parse(JSON.stringify(state));
      newState.mail.feedbackTypeList = payload.data;
      return {
        ...state,
        ...newState,
      };
    },
  },
};

export default Model;
